package com.authsphere.security.social.common;

import com.google.common.collect.Maps;
import me.zhyd.oauth.request.AuthRequest;

import java.util.Map;
import java.util.Set;
import java.util.function.BiFunction;

/**
 * @program: AuthSphere
 * @description:
 * @author: YuKai Fan
 * @create: 2025/3/19 21:35
 **/
public class AuthRequestFactory {
    private final static Map<String, AuthRequest> AUTH_REQUEST_MAP = Maps.newConcurrentMap();

    /**
     * 获取认证类型
     * @return
     */
    public static Set<String> getAuthType() {
        return AUTH_REQUEST_MAP.keySet();
    }
    /**
     * register
     * @param type type
     * @param authRequest authRequest
     */
    public static void register(String type, AuthRequest authRequest) {
        if (AUTH_REQUEST_MAP.containsKey(type)) {
            return;
        }
        AUTH_REQUEST_MAP.put(type, authRequest);
    }

    /**
     * getAuthRequest
     * @param type type
     * @return AuthRequest
     */
    public static AuthRequest getAuthRequest(String type) {
        return AUTH_REQUEST_MAP.get(type);
    }

    /**
     * getAuthRequest
     * @param type type
     * @return AuthRequest
     */
    public static AuthRequest getAuthRequest(String type, BiFunction<String, AuthRequest, AuthRequest> biFunction) {
        return AUTH_REQUEST_MAP.computeIfPresent(type, biFunction);
    }
}
